const vm = new Vue({
    el: '#main',
    data: {
        bankName: '',
        userAccount: '',
        userName: '',
        accountType: 'private',
        reqData: {
            bankName: '',
        },
    },
    methods: {},
});

function apiready() {
    main();

}

function main() {
    fxj.fixLayout();
    initBankName();
}

async function submit() {
    if (!isExist(vm.bankName)) {
        toast('请选择开户银行名称');
        return;
    }
    if (!isExist(vm.userAccount)) {
        toast('请输入开户银行账号');
        return;
    }
    if (!isExist(vm.userName)) {
        toast('请输入开户人姓名');
        return;
    }
    const close = fxj.dialog.loading();
    const reqData = {
        accountManagement: '',
        type: 1,
        truename: vm.userName,
        account: vm.userAccount,
        account_type: vm.reqData.bankName.split(';')[0],
    };
    const res = await ajax({
        url: 'home/userCenter/accountManagement',
        data: reqData,
    });
    close();
    mui.toast(res.msg);
    if (res.err === 0) {
        api.execScript({
            name: 'yollon_add',
            script: 'reqAccountList()',
        });
        setTimeout(() => {
            closeToWin('yollon_add');
        }, 1500);
    }
}

function initBankName() {
    const nationEl = document.getElementById('bankName');
    const data = [
        {
            text: '工商银行',
            value: 'GSYH;3',
        },
        {
            text: '建设银行',
            value: 'JSYH;4',
        },
        {
            text: '中国银行',
            value: 'ZGYH;5',
        },
        {
            text: '农业银行',
            value: 'NYYH;6',
        },
        {
            text: '交通银行',
            value: 'JTYH;7',
        },
        {
            text: '招商银行',
            value: 'ZSYH;8',
        },
        {
            text: '中信银行',
            value: 'ZXYH;9',
        },
        {
            text: '民生银行',
            value: 'MSYH;10',
        },
        {
            text: '兴业银行',
            value: 'XYYH;11',
        },
        {
            text: '浦发银行',
            value: 'PFYH;12',
        },
        {
            text: '邮政储蓄',
            value: 'YZCX;13',
        },
        {
            text: '光大银行',
            value: 'GDYH;14',
        },
        {
            text: '平安银行',
            value: 'PAYH;15',
        },
        {
            text: '华夏银行',
            value: 'HXYH;16',
        },
        {
            text: '北京银行',
            value: 'BJYH;17',
        },
        {
            text: '广发银行',
            value: 'GFYH;18',
        },
    ];
    const picker = new Picker({
        data: [data],
        selectedIndex: [0],
        title: '开户银行名称',
    });
    picker.on('picker.valuechange', (selectedVal, selectedIndex) => {
        vm.bankName = data[selectedIndex].text;
        vm.reqData.bankName = selectedVal[0];
    });

    nationEl.addEventListener('click', () => {
        picker.show();
    });
}
